//
//  VocherHelper.m
//  meiyinxiang
//
//  Created by 媒印象 on 29/11/2017.
//  Copyright © 2017 hbjApple. All rights reserved.
//

#import "VocherHelper.h"
@implementation VocherHelper
+ (VocherHelper *)shared{
    static VocherHelper *helper = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[VocherHelper alloc] init];
    });
    return helper;
}
- (NSString *)figureOutWithAllMoney:(NSString *)allMoney withVocher:(VocherViewModel *)vocher{
    //当是无条件现金红包体验卷
    if ([vocher.condition isEqualToString:@"0"]) {
        return allMoney.floatValue > vocher.num.floatValue ? [NSString stringWithFormat:@"%.1f",allMoney.floatValue - vocher.num.floatValue] : @"0";
    }else{//满减现金红包
        return allMoney.floatValue > vocher.num.floatValue ?  [NSString stringWithFormat:@"%.1f",allMoney.floatValue - vocher.num.floatValue] : [NSString stringWithFormat:@"%.1f",vocher.condition.floatValue - vocher.num.floatValue];
    }
 //   return nil;
}
- (BOOL)figureOutMoney:(NSString *)money
            moneyCount:(NSString *)moneyCount{
    if (money.floatValue < 1) {
        ShowSVProgressErrorMessage(@"您发的红包金额不能小于1.0元");
       // [SVProgressHUD showErrorWithStatus:@"您发的红包金额不能小于1.0元"];
        return NO;
    }
    CGFloat minMoney = money.floatValue / moneyCount.integerValue;
    NSString *accurateMoney = [NSString stringWithFormat:@"%.7f",minMoney];
    if (accurateMoney.floatValue < 0.009999999 ) {
        ShowSVProgressErrorMessage(@"您发的单个红包金额不能小于0.01元");

       // [SVProgressHUD showErrorWithStatus:@"您发的单个红包金额不能小于0.01元"];
        return NO;
    }else if ( moneyCount.integerValue > 200){
        ShowSVProgressErrorMessage(@"您发的红包个数不能大于200个");

      //  [SVProgressHUD showErrorWithStatus:@"您发的红包个数不能大于200个"];
        return NO;
    }else if (money.floatValue <= 0 || money.length == 0 || moneyCount.integerValue <= 0 || moneyCount.length == 0 ) {
        ShowSVProgressErrorMessage(@"请塞入正确的红包金额!");

      //  [SVProgressHUD showErrorWithStatus:@"请塞入正确的红包金额!"];
        return NO;
    }
    return YES;
}
@end
